/**
 * Created by Administrator on 2016/7/29.
 */
"use strict";
swan_pc
    .controller("AddMessageController",function($scope,getMyFriend,messageManage,GetAccountInfo,$q){
        $scope.newMessage={
            "content": null,
            "fromId": 0,
            "fromType": "INDIVIDUAL",
            "isRead": false,
            "isResolved": false,
            "reply": null,
            "title": null,
            "toId": 0,
            "toType": "INDIVIDUAL",
            "type": "MSG_NORMAL"
        }
        $scope.firendWhoSendMePermission=[];
        getMyFriend.query(function(result){
            $scope.firendWhoSendMePermission=result;
        })
        $scope.resetMessage=function(){
            $scope.newMessage={
                "content": null,
                "fromId": 0,
                "fromType": "INDIVIDUAL",
                "isRead": false,
                "isResolved": false,
                "reply": null,
                "title": null,
                "toId": 0,
                "toType": "INDIVIDUAL",
                "type": "normalMessage"
            }
        }
        $scope.sendMessage=function() {
            //console.log($scope.newMessage);
            var def=$q.defer();
            var pro=def.promise;
            GetAccountInfo.get(function(result){
                    $scope.presentAccountInfo=result;
                    $scope.newMessage.fromId=$scope.presentAccountInfo.id;
                    def.resolve();
                },
                function(result){
                    def.reject();
                })
            pro.then(function(){
                messageManage.save($scope.newMessage, function (result) {
                    swal("发送信息成功", "", "success");
                }, function (result) {
                    swal("发送信息失败", "", "error");
                })
            })

        }
    })